﻿using System.Globalization;
using System.Windows.Data;

namespace TianlalaHSB.ViewModels;

public class StringToTimeConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is string)
        {
            var formatInput = "HHmmss"; // 输入的日期格式
            var formatOutput = "HH:mm:ss"; // 输出的日期格式

            // 使用ParseExact将字符串转换为DateTime对象
            var date = DateTime.ParseExact((string)value, formatInput, CultureInfo.InvariantCulture);

            // 使用ToString方法和指定的格式将DateTime对象转换回字符串
            return date.ToString(formatOutput, CultureInfo.InvariantCulture);
        }

        return "";
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        // 如果需要双向转换，这里实现转换回bool的逻辑
        throw new NotImplementedException();
    }
}